/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-06-04 07:54:56
 * @LastEditTime: 2022-06-28 20:35:10
 * @LastEditors: liutq
 * @Reference:
 */
package goods

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/maxyang107/jinglan/common"
	"github.com/maxyang107/jinglan/service"
	"github.com/maxyang107/jinglan/utils"
)

/**
 * @description: 方法描述：抽签写入
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func AddDrawRecord(c *gin.Context) {
	var query_ common.DrawQuery

	if err := c.ShouldBind(&query_); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}

	userid, exists := c.Get("UserId")

	if !exists {
		common.ResponseToJson(http.StatusOK, common.NotAuth, "token解析失败", c)
		return
	}

	query_.UserId = utils.InterfaceToUser(userid)

	err := service.DrawService.InsertDrawRecord(query_)
	if err != nil {
		common.ResponseToJson(http.StatusOK, common.Fail, err.Error(), c)
		return
	}
	common.ResponseToJson(http.StatusOK, common.Ok, "抽签成功", c)
}
